package com.fwx.system.controller;

import com.fwx.common.core.domain.domain.R;
import com.fwx.system.Service.ISySUserService;
import com.fwx.system.domain.LoginDTO;
import com.fwx.system.domain.SysUser;
import com.fwx.system.domain.SysUserSaveDTO;
import com.fwx.system.domain.SysUserVo;
import com.fwx.system.mapper.SysUserMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jdk.jfr.Percentage;
import lombok.Getter;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员接口")
public class SysUserController {
    @Autowired
    private ISySUserService sySUserService;
    @Autowired
    private SysUserMapper sysUserMapper;

    //登录成功或者失败 true / false  int code 0 / 1
    //失败原因 String msg
    //swagger生成接口文档
    @PostMapping("/login")
    @Operation(summary = "管理员登录",description = "根据账号密码进行管理员登录")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    public R<String> login(@RequestBody LoginDTO loginDTO){
        return sySUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }



    //管理员的增删改查
    //接口地址：/sysUser/add
    //请求方法 post
    @PostMapping("/add")
    @Operation(summary = "新增管理员",description = "根据提供的信息，新增管理员")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return null;
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户",description = "通过用户id删除用户")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH,description = "用户id")
    })
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    public R<Void> delete(@PathVariable SysUserSaveDTO sysUserSaveDTO) {
        return null;
    }

    @Operation(summary = "用户详情",description = "根据查询条件查询用户详情")
    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId",in = ParameterIn.QUERY,description = "用户Id"),
            @Parameter(name = "sex",in = ParameterIn.QUERY,description = "用户性别")
    })
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    public R<SysUserVo> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex) {
        return null;
    }
}
